import Cookies from 'js-cookie'
import { noticeApi } from '@/feature/mms/infra/api/noticeApi'

const state = {
  sidebar: {
    // opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    opened: true,
    withoutAnimation: false
  },
  dataCount: {
    badComment: {},
    delivery: {},
    complainData: {},
    competingStoreBlogger: {}
  },
  unReadMsgCount: 0,
  device: 'desktop'
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    // state.sidebar.opened = !state.sidebar.opened
    // state.sidebar.withoutAnimation = false
    // if (state.sidebar.opened) {
    //   Cookies.set('sidebarStatus', 1)
    // } else {
    //   Cookies.set('sidebarStatus', 0)
    // }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    // Cookies.set('sidebarStatus', 0)
    // state.sidebar.opened = false
    // state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    // state.device = device
  },
  setUnReadMsgCount: (state, data) => {
    state.unReadMsgCount = data
  },
  setBadCommentDataCount: (state, data) => {
    state.dataCount.badComment = data
  },
  setDeliveryDataCount: (state, data) => {
    state.dataCount.delivery = data
  },
  setComplainDataCount: (state, data) => {
    state.dataCount.complainData = data
  },
  setCompetingStoreBloggerCount: (state, data) => {
    state.dataCount.competingStoreBlogger = data
  }
}

const actions = {
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  fetchUnReadMsgCount({ commit, state }) {
    noticeApi.notReadCount().then(data => {
      commit('setUnReadMsgCount', data)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
